package com.jlc.book.shop.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jlc.book.shop.delegate.UserDelegate;
import com.jlc.book.shop.validator.JLCDataValidator;

public class ForgetPasswordAction {

	public String searchPassword(HttpServletRequest request,
			HttpServletResponse response) {
		
		
		String page="forgetPasswordDef.jsp";
		String uname=request.getParameter("uname");
		String email=request.getParameter("email");
		boolean interactWithDB=true;
		
		if(!JLCDataValidator.validateRequired(uname))
		{
			request.setAttribute("uname", "Username is required");
			interactWithDB=false;
		}
		if(!JLCDataValidator.validateRequired(email))
		{
			request.setAttribute("email", "Email is required");
			interactWithDB=false;
		}
		else if(!JLCDataValidator.validateEmail(email))
		{
			request.setAttribute("email", "Please enter valid email id");
			interactWithDB=false;
		}
		if(interactWithDB)
		{
			String password=UserDelegate.searchPassword(uname,email);
			if(password!=null)
			{
				request.setAttribute("PASSWORD", password);
			}
			else
			{
				request.setAttribute("forgetPasswordError", "Provided information is invalid");
			}
		}
		return page;
	}

}
